<template>
    <div>
        <table class="wq text-center" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_list_caption">
                <td>号</td>
                <td>赔率</td>
                <td>金额</td>
                <td>号</td>
                <td>赔率</td>
                <td>金额</td>
                <td>号</td>
                <td>赔率</td>
                <td>金额</td>
                <td>号</td>
                <td>赔率</td>
                <td>金额</td>
            </tr>
            <tr class="t_td_text">

                <td width="10%" class="caption_1"><span class="No_gd01"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:01']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:01']" @focus="quickbetFuns($event,params.levellottery + ':单码:01')"></td>

                <td width="10%" class="caption_1"><span class="No_gd06"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:06']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:06']" @focus="quickbetFuns($event,params.levellottery + ':单码:06')"></td>

                <td width="10%" class="caption_1"><span class="No_gd11"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:11']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:11']" @focus="quickbetFuns($event,params.levellottery + ':单码:11')"></td>
                <td width="10%" class="caption_1"><span class="No_gd16"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:16']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:16']" @focus="quickbetFuns($event,params.levellottery + ':单码:16')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1"><span class="No_gd02"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:02']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:02']" @focus="quickbetFuns($event,params.levellottery + ':单码:02')"></td>
                <td width="10%" class="caption_1"><span class="No_gd07"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:07']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:07']" @focus="quickbetFuns($event,params.levellottery + ':单码:07')"></td>
                <td width="10%" class="caption_1"><span class="No_gd12"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:12']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:12']" @focus="quickbetFuns($event,params.levellottery + ':单码:12')"></td>
                <td width="10%" class="caption_1"><span class="No_gd17"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:17']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单码:17']" @focus="quickbetFuns($event,params.levellottery + ':单码:17')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1"><span class="No_gd03"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:03']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:03']" @focus="quickbetFuns($event,params.levellottery + ':单码:03')"></td>
                <td width="10%" class="caption_1"><span class="No_gd08"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:08']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:08']" @focus="quickbetFuns($event,params.levellottery + ':单码:08')"></td>
                <td width="10%" class="caption_1"><span class="No_gd13"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:13']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:13']" @focus="quickbetFuns($event,params.levellottery + ':单码:13')"></td>
                <td width="10%" class="caption_1"><span class="No_gd18"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:18']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:18']" @focus="quickbetFuns($event,params.levellottery + ':单码:18')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1"><span class="No_gd04"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:04']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:04']" @focus="quickbetFuns($event,params.levellottery + ':单码:04')"></td>
                <td width="10%" class="caption_1"><span class="No_gd09"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:09']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:09']" @focus="quickbetFuns($event,params.levellottery + ':单码:09')"></td>
                <td width="10%" class="caption_1"><span class="No_gd14"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:14']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:14']" @focus="quickbetFuns($event,params.levellottery + ':单码:14')"></td>
                <td width="10%" class="caption_1"><span class="No_gd19"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:19']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:19']" @focus="quickbetFuns($event,params.levellottery + ':单码:19')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1"><span class="No_gd05"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:05']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:05']" @focus="quickbetFuns($event,params.levellottery + ':单码:05')"></td>
                <td width="10%" class="caption_1"><span class="No_gd10"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:10']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:10']" @focus="quickbetFuns($event,params.levellottery + ':单码:10')"></td>
                <td width="10%" class="caption_1"><span class="No_gd15"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:15']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:15']" @focus="quickbetFuns($event,params.levellottery + ':单码:15')"></td>
                <td width="10%" class="caption_1"><span class="No_gd20"></span></td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单码:20']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':单码:20']" @focus="quickbetFuns($event,params.levellottery + ':单码:20')"></td>
            </tr>
        </table>
        <table class="wq text-center" style="margin-top:0px;" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_td_text">
                <td width="10%" class="caption_1">大</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':大小:大']}}</td>
                <td><input type="text" class="moneyinp"  v-model="moneydata[params.levellottery + ':大小:大']" @focus="quickbetFuns($event,params.levellottery + ':大小:大')"></td>
                <td width="10%" class="caption_1">单</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单双:单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单双:单']" @focus="quickbetFuns($event,params.levellottery + ':单双:单')"></td>
                <td width="10%" class="caption_1">合数单</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':和数单双:单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':和数单双:单']" @focus="quickbetFuns($event,params.levellottery + ':和数单双:单')"></td>
                <td width="10%" class="caption_1">尾大</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':尾数大小:大']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':尾数大小:大']" @focus="quickbetFuns($event,params.levellottery + ':尾数大小:大')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">小</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':大小:小']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':大小:小']" @focus="quickbetFuns($event,params.levellottery + ':大小:小')"></td>
                <td width="10%" class="caption_1">双</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':单双:双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':单双:双']" @focus="quickbetFuns($event,params.levellottery + ':单双:双')"></td>
                <td width="10%" class="caption_1">合数双</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':和数单双:双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':和数单双:双']" @focus="quickbetFuns($event,params.levellottery + ':和数单双:双')"></td>
                <td width="10%" class="caption_1">尾小</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':尾数大小:小']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':尾数大小:小']" @focus="quickbetFuns($event,params.levellottery + ':尾数大小:小')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">东</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':方位:东']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':方位:东']" @focus="quickbetFuns($event,params.levellottery + ':方位:东')"></td>
                <td width="10%" class="caption_1">南</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':方位:南']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':方位:南']" @focus="quickbetFuns($event,params.levellottery + ':方位:南')"></td>
                <td width="10%" class="caption_1">西</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':方位:西']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':方位:西']" @focus="quickbetFuns($event,params.levellottery + ':方位:西')"></td>
                <td width="10%" class="caption_1">北</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':方位:北']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':方位:北']" @focus="quickbetFuns($event,params.levellottery + ':方位:北')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">中</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':中发白:中']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':中发白:中']" @focus="quickbetFuns($event,params.levellottery + ':中发白:中')"></td>
                <td width="10%" class="caption_1">发</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':中发白:发']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':中发白:发']" @focus="quickbetFuns($event,params.levellottery + ':中发白:发')"></td>
                <td width="10%" class="caption_1">白</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':中发白:白']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':中发白:白']" @focus="quickbetFuns($event,params.levellottery + ':中发白:白')"></td>
                <td colspan="3"></td>
            </tr>
            <tr class="t_td_text" v-if="ratedata[ params.levellottery + ':龙虎:虎']">
                <td width="10%" class="caption_1">龙</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':龙虎:龙']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':龙虎:龙']" @focus="quickbetFuns($event,params.levellottery + ':龙虎:龙')"></td>
                <td width="10%" class="caption_1">虎</td>
                <td class="colorRed bolds odds">{{ratedata[ params.levellottery + ':龙虎:虎']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata[params.levellottery + ':龙虎:虎']" @focus="quickbetFuns($event,params.levellottery + ':龙虎:虎')"></td>
                <td colspan="6"></td>
            </tr>
            
        </table>
    </div>
</template>
<script>
    var timer = null;
    import Vue from 'vue'
    import axios from 'axios'
    import {lotterytype} from '../../../../assets/js/lotterytype.js'

    export default {
        name: "GdklsfBall",
        props: {  //普通类型：String、Number、Boolean、Null    引用类型： Array、Object
            betmoney: {   //   快捷下注金额
                type: String,
                required: true
            },
            resetinp: {   //   是否重填已下注金额  0为未下注  其他为已下注
                type: Number,
                required: true
            },
            openBet: {  //开奖  可下注
                type: Boolean,
                required: true
            },
            ninetime: {  //90s
                type: Number,
                required: true
            },
        },
        data(){
            return{
                ratedata: {},  //实时赔率
                params: {},  //菜单
                moneydata: {},
                betdataArr: [],  //下注 提交data
                nowitem: '',  //当前操作的下注item号
                arr: [],  //
            }
        },
        methods: {
            init(){
                // console.log(this.$route.query.levelid);
                var _this = this;
                
                this.params = lotterytype.apiParams(this.$route.query.id,this.$route.query.levelid);

                if(window.localStorage.Authorization){
                    
                    _this.$httpGet('/api/game/listRate/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                        
                        if(response.status == 200){
                            _this.ratedata = response.data.rates;

                            if(response.data.need){
                                _this.$httpPost('/api/setting/rateItem/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                                
                                    if(response.status == 200){
                                        
                                    }

                                });
                            }
                        }

                    });

                }
                
            },
            inits(){
                // console.log(this.$route.query.levelid);
                var _this = this;
                
                this.params = lotterytype.apiParams(this.$route.query.id,this.$route.query.levelid);

                if(window.localStorage.Authorization){
                    
                    if (timer) {
                        clearInterval(timer);
                        timer = null;
                    }

                    _this.$httpGet('/api/game/listRate/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                        
                        if(response.status == 200){
                            _this.ratedata = response.data.rates;

                            if(response.data.need){
                                _this.$httpPost('/api/setting/rateItem/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                                
                                    if(response.status == 200){
                                        
                                    }

                                });
                            }

                            timer = setInterval(() => {
                                _this.inits();
                            }, 10 * 1000)
                        }

                    });
                }
                
            },
            //快捷下注
            quickbetFuns(ev,item,odds){
                var _this = this;
                if(_this.betmoney){

                    // Vue.set方法用来新增对象的属性。
                    _this.$set(_this.moneydata, item, _this.betmoney);
                    
                }
                _this.nowitem = item;
                
            },
            
        },
        mounted(){
            this.inits();
        },
        beforeDestroy(){
            clearInterval(timer);
        },
        watch :{
            resetinp: function(now,old){

                if(now != 0){   //重填下注金额

                    this.moneydata = {};  //清空所有下注金额
                    this.betdataArr = [];
                    this.arr = [];

                }
            },
            moneydata: {
                
                //注意：当观察的数据为对象或数组时，curVal和oldVal是相等的，因为这两个形参指向的是同一个数据对象
                handler(newValue, oldValue) {

                    var _this = this;
                    //  console.log(newValue[this.nowitem],newValue,this.nowitem)

                    if(newValue[_this.nowitem] != '' && newValue[_this.nowitem] != '0' && newValue[_this.nowitem] != undefined){

                        if (_this.arr.indexOf(_this.nowitem) == -1) {
                            _this.arr.push(_this.nowitem);
                            _this.betdataArr.push({'item': _this.nowitem,'value': newValue[_this.nowitem],'balls': []});
                        } else {
                            for(var i=0;i<_this.betdataArr.length;i++){

                                if(_this.nowitem == _this.betdataArr[i].item){
                                    _this.betdataArr[i].value= newValue[_this.nowitem];
                                }
                            }
                        }


                    }else{  //当前改变值为空

                        for(var i=0;i<_this.betdataArr.length;i++){

                            if(_this.betdataArr[i].item == _this.nowitem){
                                _this.betdataArr.splice(i,1);
                            }

                        }

                    }

                    var betdataObj = {};
                    betdataObj.game = _this.params.nowlottery;
                    betdataObj.items = _this.betdataArr;
                    
                    if(_this.betdataArr.length == 0){
                        _this.$emit('betdataObj',{});
                    }else{
                        _this.$emit('betdataObj',betdataObj);
                    }
                    // console.log('------watch',betdataObj);

                },
        　　　　 deep: true
            },
            openBet: function(now,old){
                console.log(now,old);
                this.init();
            },
            ninetime: function(now,old){
                console.log('------------90s  刷新');
                //90s  刷新数据
                this.init();
            },
        },
    }
</script>
